package lzzy.edu.cn.demothymeleaf.service;

import lzzy.edu.cn.demothymeleaf.entity.Comment;
import lzzy.edu.cn.demothymeleaf.repository.CommentReository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    @Autowired
    CommentReository commentRepository;

    public List<Comment> selectCommentAll() {
        return commentRepository.findAll();
    }

    public List<Comment> selectByAId(Integer aId) {
        return commentRepository.selectByAId(aId);
    }

    public void addComment(String author, String content,Integer aId) {
        Comment comment = new Comment();
        comment.setAuthor(author);
        comment.setContent(content);
        comment.setAId(aId);
        commentRepository.save(comment);
    }
}